﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Diagnostics;
using Microsoft.Office.Interop.Word;
using System.Globalization;
using System.Management;
using iTextSharp.text.pdf;

public class ContractDataForLinq
{
    public int contractid{ get; set; }
    public System.Nullable<int> Contract_Main{ get; set; }
    public int xthid{ get; set; }
    public string dh{ get; set; }
    public string sm{ get; set; }
    public string csm { get; set; }
    public string zuozhe{ get; set; }
    public string zrbj{ get; set; }
    public string zhuzuoxingshi{ get; set; }
    public string zhuzuofangshi{ get; set; }
    public string danwei{ get; set; }
    public string lianxiren{ get; set; }
    public string contractno{ get; set; }
    public string diqu{ get; set; }
    public string chubanxingshi{ get; set; }
    public string wenti{ get; set; }
    public string qtwenti{ get; set; }
    public System.Nullable<System.DateTime> jiaogaoshijian{ get; set; }
    public string jiafang{ get; set; }
    public System.Nullable<int> ys{ get; set; }
    public string cssj{ get; set; }
    public string zzyq{ get; set; }
    public string gc{ get; set; }
    public string content{ get; set; }
    public System.Nullable<int> usersyscode{ get; set; }
    public System.Nullable<int> zs{ get; set; }
    public string kb{ get; set; }
    public string fmyz{ get; set; }
    public string fmyz1{ get; set; }
    public string fmyzzhi{ get; set; }
    public string fmyzzhi1{ get; set; }
    public string hcyz{ get; set; }
    public string hcyz1{ get; set; }
    public string hcyzzhi{ get; set; }
    public string hcyzzhi1{ get; set; }
    public string ccyz{ get; set; }
    public string ccyz1{ get; set; }
    public string nwyz{ get; set; }
    public string nwyz1{ get; set; }
    public string baozhuang{ get; set; }
    public string qtcontent{ get; set; }
    public System.Nullable<int> yangshu{ get; set; }
    public string zhekou{ get; set; }
    public string jingshouyi{ get; set; }
    public System.Nullable<int> goushu{ get; set; }
    public System.Nullable<decimal> shoukuan{ get; set; }
    public string shoukuandate{ get; set; }
    public string youxiaoqi{ get; set; }
    public System.Nullable<System.DateTime> indate{ get; set; }
    public System.Nullable<int> okUserId{ get; set; }
    public string OkUserName{ get; set; }
    public System.Nullable<int> okchecked{ get; set; }
    public System.Nullable<System.DateTime> okdate{ get; set; }
    public string okcontent{ get; set; }
    public System.Nullable<int> isStatus{ get; set; }
    public System.Nullable<int> UserId{ get; set; }
    public string UserName{ get; set; }
    public System.Nullable<int> Leibie{ get; set; }
    public string Shuoming{ get; set; }
    public string CaiwuShuoming{ get; set; }
    public System.Nullable<int> echecked{ get; set; }
    public System.Nullable<System.DateTime> createdate{ get; set; }
    public string ContractFile{ get; set; }
    public string IdCardZ{ get; set; }
    public string IdCardF{ get; set; }
    public string IdCardName{ get; set; }
    public string PrintFileName{ get; set; }
}

public class ContractData
{
    public string ContractNo { get; set; }
    public int? ContractMain { get; set; }
    public string Chubanxingshi { get; set; }
    public string Sm { get; set; }
    public string Csm { get; set; }
    public string Zuozhe { get; set; }
    public string Zhuzuofangshi { get; set; }
    public string Danwei { get; set; }
    public string Zrbj { get; set; }
    public string Jiafang { get; set; }
    public int? eCheck { get; set; }
    public string Diqu { get; set; }
    public string Wenti { get; set; }
    public string Qtwenti { get; set; }
    public DateTime? Jiaogaoshijian { get; set; }
    public int? Zs { get; set; }
    public string Kb { get; set; }
    public string Fmyz { get; set; }
    public string Fmyz1 { get; set; }
    public string Hcyz { get; set; }
    public string Hcyz1 { get; set; }
    public string Ccyz { get; set; }
    public string Ccyz1 { get; set; }
    public string Nwyz { get; set; }
    public string Nwyz1 { get; set; }
    public string Baozhuang { get; set; }
    public DateTime? Cssj { get; set; }
    public string Qtcontent { get; set; }
    public int? Yangshu { get; set; }
    public string Zhekou { get; set; }
    public int? Goushu { get; set; }
    public Decimal? Shoukuan { get; set; }
    public DateTime? Shoukuandate { get; set; }
    public DateTime? Indate { get; set; }
    public string Jingshouyi { get; set; }
    public string Content { get; set; }
    public int? Youxiaoqi { get; set; }
    public int? isStatus { get; set; }
    public string PrintFileName { get; set; }
}
//// <summary>
/// 人民币大小写金额转换
/// </summary>
public class RMBCapitalization
{
    private const string DXSZ = "零壹贰叁肆伍陆柒捌玖";
    private const string DXDW = "毫厘分角元拾百千万拾百千亿拾百千万兆拾百千万亿京拾百千万亿兆垓";
    private const string SCDW = "元拾百千万亿京兆垓";

    /// <summary>
    /// 转换整数为大写金额
    /// 最高精度为垓，保留小数点后4位，实际精度为亿兆已经足够了，理论上精度无限制，如下所示：
    /// 序号:...30.29.28.27.26.25.24  23.22.21.20.19.18  17.16.15.14.13  12.11.10.9   8 7.6.5.4  . 3.2.1.0
    /// 单位:...垓兆亿萬仟佰拾        京亿萬仟佰拾       兆萬仟佰拾      亿仟佰拾     萬仟佰拾元 . 角分厘毫
    /// 数值:...1000000               000000             00000           0000         00000      . 0000
    /// 下面列出网上搜索到的数词单位：
    /// 元、十、百、千、万、亿、兆、京、垓、秭、穰、沟、涧、正、载、极

    /// </summary>
    /// <param name="capValue">整数值</param>
    /// <returns>返回大写金额</returns>
    private string ConvertIntToUppercaseAmount(string capValue)
    {
        string currCap = "";    //当前金额
        string capResult = "";  //结果金额
        string currentUnit = "";//当前单位
        string resultUnit = ""; //结果单位            
        int prevChar = -1;       //上一位的值
        int currChar = 0;        //当前位的值
        int posIndex = 4;        //位置索引，从"元"开始

        if (Convert.ToDouble(capValue) == 0) return "零元";
        for (int i = capValue.Length - 1; i >= 0; i--)
        {
            currChar = Convert.ToInt16(capValue.Substring(i, 1));

            if (posIndex > 30)
            {
                //已超出最大精度"垓"。注：可以将30改成22，使之精确到兆亿就足够了
                break;
            }
            else if (currChar != 0)
            {
                //当前位为非零值，则直接转换成大写金额
                currCap = DXSZ.Substring(currChar, 1) + DXDW.Substring(posIndex, 1);
            }
            else
            {
                //防止转换后出现多余的零,例如：3000020
                switch (posIndex)
                {
                    case 4: currCap = "元"; break;
                    case 8: currCap = "万"; break;
                    case 12: currCap = "亿"; break;
                    case 17: currCap = "兆"; break;
                    case 23: currCap = "京"; break;
                    case 30: currCap = "垓"; break;
                    default: break;
                }
                if (prevChar != 0)
                {
                    if (currCap != "")
                    {
                        if (currCap != "元") currCap += "零";
                    }
                    else
                    {
                        currCap = "零";
                    }
                }
            }

            //对结果进行容错处理               
            if (capResult.Length > 0)
            {
                resultUnit = capResult.Substring(0, 1);
                currentUnit = DXDW.Substring(posIndex, 1);
                if (SCDW.IndexOf(resultUnit) > 0)
                {
                    if (SCDW.IndexOf(currentUnit) > SCDW.IndexOf(resultUnit))
                    {
                        capResult = capResult.Substring(1);
                    }
                }
            }
            capResult = currCap + capResult;
            prevChar = currChar;
            posIndex += 1;
            currCap = "";
        }
        return capResult;
    }

    /// <summary>
    /// 转换小数为大写金额
    /// </summary>
    /// <param name="capValue">小数值</param>
    /// <param name="addZero">是否增加零位</param>
    /// <returns>返回大写金额</returns>
    private string ConvertDecToUppercaseAmount(string capValue, bool addZero)
    {
        string currCap = "";
        string capResult = "";
        int prevChar = addZero ? -1 : 0;
        int currChar = 0;
        int posIndex = 3;

        if (Convert.ToInt16(capValue) == 0) return "";
        for (int i = 0; i < capValue.Length; i++)
        {
            currChar = Convert.ToInt16(capValue.Substring(i, 1));
            if (currChar != 0)
            {
                currCap = DXSZ.Substring(currChar, 1) + DXDW.Substring(posIndex, 1);
            }
            else
            {
                if (Convert.ToInt16(capValue.Substring(i)) == 0)
                {
                    break;
                }
                else if (prevChar != 0)
                {
                    currCap = "零";
                }
            }
            capResult += currCap;
            prevChar = currChar;
            posIndex -= 1;
            currCap = "";

        }
        return capResult;
    }

    /// <summary>
    /// 人民币大写金额
    /// </summary>
    /// <param name="value">人民币数字金额值</param>
    /// <returns>返回人民币大写金额</returns>
    public string RMBAmount(double value)
    {
        string capResult = "";
        string capValue = string.Format("{0:f4}", value);       //格式化
        int dotPos = capValue.IndexOf(".");                     //小数点位置
        bool addInt = (Convert.ToInt32(capValue.Substring(dotPos + 1)) == 0);//是否在结果中加"整"
        bool addMinus = (capValue.Substring(0, 1) == "-");      //是否在结果中加"负"
        int beginPos = addMinus ? 1 : 0;                        //开始位置
        string capInt = capValue.Substring(beginPos, dotPos);   //整数
        string capDec = capValue.Substring(dotPos + 1);         //小数

        if (dotPos > 0)
        {
            capResult = ConvertIntToUppercaseAmount(capInt) +
            ConvertDecToUppercaseAmount(capDec, Convert.ToDouble(capInt) != 0 ? true : false);
        }
        else
        {
            capResult = ConvertIntToUppercaseAmount(capDec);
        }
        if (addMinus) capResult = "负" + capResult;
        if (addInt){
            capResult += "整";
        }
        return capResult;
    }

}

public class DataCheck
{
    public string DataCheckResult(string Data)
    {
        return string.IsNullOrEmpty(Data) ? "    " : " " + Data + " ";
    }
    public string DataCheckResult(DateTime? Data)
    {
        return Data.HasValue ? Data.Value.ToString(" yyyy年MM月dd日 ") : "     年   月   日 ";
    }
    public string DataCheckResult(int? Data)
    {
        return Data.HasValue ? " " + Data.Value.ToString() + " " : "   ";
    }
    public double DataCheckResult(double? Data)
    {
        return Data.HasValue ? Data.Value : 0;
    }
    public string DataCheckResult(double? Data, int flag)
    {
        return Data.HasValue ? " " + Data.Value + " " : "   ";
    }
}

public class ContractOperator
{
    public bool AddWatermark(string inputPath, string outputPath, string watermarkPath, string ContractNo)
    {
        try
        {
            PdfReader pdfReader = new PdfReader(inputPath);
            int numberOfPages = pdfReader.NumberOfPages;

            iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);
            float width = psize.Width;
            float height = psize.Height;

            FileStream outputStream = new FileStream(outputPath, FileMode.Create);
            PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream);
            PdfContentByte waterMarkContent;
            BaseFont font = BaseFont.CreateFont(HttpContent.Current.Server.MapPath("msyh.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            iTextSharp.text.Image image = null;
            if (string.IsNullOrEmpty(watermarkPath))
            {
                Stream s = GetType().Assembly.GetManifestResourceStream("WatermarkTool.wm.png");
                image = iTextSharp.text.Image.GetInstance(s);
            }
            else
            {
                image = iTextSharp.text.Image.GetInstance(watermarkPath);
            }
            image.SetAbsolutePosition(10, 65);
            PdfGState gs = new PdfGState();
            for (int i = 1; i <= numberOfPages; i++)
            {
                if (i == 1)
                {
                    waterMarkContent = pdfStamper.GetOverContent(i);
                    gs.FillOpacity = 0.6f;
                    waterMarkContent.SetGState(gs);
                    //开始写入文本
                    waterMarkContent.BeginText();
                    waterMarkContent.SetColorFill(iTextSharp.text.BaseColor.LIGHT_GRAY);
                    waterMarkContent.SetFontAndSize(font, 20);
                    waterMarkContent.SetTextMatrix(0, 0);
                    waterMarkContent.ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, ContractNo, width - 100, height - 50, 0);

                }
                waterMarkContent = pdfStamper.GetUnderContent(i);
                //image.GrayFill = 0.6f;
                waterMarkContent.AddImage(image);
            }
            pdfStamper.Close();
            pdfReader.Close();
            outputStream.Close();
            return true;
        }
        catch (Exception ex)
        {
           // error = ex.StackTrace;
            return false;
        }
    }
}

public class ContractTranslate
{
    public ContractTranslate(int contractId, string contractPath, string flexPath, bool isCreate)
    {
        SuccessMark = false;
        ContractPath = contractPath;
        FlexPath = flexPath;
        ErrorStr = @"<script type='text/javascript'>$('#loadimg').hide();$('#result').html('未知错误！');</script>";
        Contract.ContractDataContext ContractDataList = new Contract.ContractDataContext(PomPublicClass.POM_ConnectionString());
        var result = from cd in ContractDataList.contract
                     join ex in ContractDataList.xtsk on cd.xthid equals ex.id
                     join q in ContractDataList.commoncongshu on ex.csmid equals q.id into qx
                     from qy in qx.DefaultIfEmpty()
                     where cd.contractid == contractId
                     select new ContractDataForLinq()
                     {
                         contractid = cd.contractid,
                         Contract_Main = cd.Contract_Main,
                         xthid = cd.xthid,
                         dh = cd.dh,
                         sm = cd.sm,
                         csm = qy.name,
                         zuozhe = cd.zuozhe,
                         zrbj = cd.zrbj,
                         zhuzuoxingshi = cd.zhuzuoxingshi,
                         zhuzuofangshi = cd.zhuzuofangshi,
                         danwei = cd.danwei,
                         lianxiren = cd.lianxiren,
                         contractno = cd.contractno,
                         diqu = cd.diqu,
                         chubanxingshi = cd.chubanxingshi,
                         wenti = cd.wenti,
                         qtwenti = cd.qtwenti,
                         jiaogaoshijian = cd.jiaogaoshijian,
                         jiafang = cd.jiafang,
                         ys = cd.ys,
                         cssj = cd.cssj,
                         zzyq = cd.zzyq,
                         gc = cd.gc,
                         content = cd.content,
                         usersyscode = cd.usersyscode,
                         zs = cd.zs,
                         kb = cd.kb,
                         fmyz = cd.fmyz,
                         fmyz1 = cd.fmyz1,
                         fmyzzhi = cd.fmyzzhi,
                         fmyzzhi1 = cd.fmyzzhi1,
                         hcyz = cd.hcyz,
                         hcyz1 = cd.hcyz1,
                         hcyzzhi = cd.hcyzzhi,
                         hcyzzhi1 = cd.hcyzzhi1,
                         ccyz = cd.ccyz,
                         ccyz1 = cd.ccyz1,
                         nwyz = cd.nwyz,
                         nwyz1 = cd.nwyz1,
                         baozhuang = cd.baozhuang,
                         qtcontent = cd.qtcontent,
                         yangshu = cd.yangshu,
                         zhekou = cd.zhekou,
                         jingshouyi = cd.jingshouyi,
                         goushu = cd.goushu,
                         shoukuan = cd.shoukuan,
                         shoukuandate = cd.shoukuandate,
                         youxiaoqi = cd.youxiaoqi,
                         indate = cd.indate,
                         okUserId = cd.okUserId,
                         OkUserName = cd.OkUserName,
                         okchecked = cd.okchecked,
                         okdate = cd.okdate,
                         okcontent = cd.okcontent,
                         isStatus = cd.isStatus,
                         UserId = cd.UserId,
                         UserName = cd.UserName,
                         Leibie = cd.Leibie,
                         Shuoming = cd.Shuoming,
                         CaiwuShuoming = cd.CaiwuShuoming,
                         echecked = cd.echecked,
                         createdate = cd.createdate,
                         ContractFile = cd.ContractFile,
                         IdCardZ = cd.IdCardZ,
                         IdCardF = cd.IdCardF,
                         IdCardName = cd.IdCardName,
                         PrintFileName = cd.PrintFileName
                     };
        List<ContractDataForLinq> CDList = result.ToList();
        if (CDList.Count > 0)
        {
            ContractData CD = ContractDataMatch(CDList[0]);
            string PrintFileName = CD.PrintFileName;
            string OldFlashPath = ContractPath + "PrintFiles/Swf/" + PrintFileName + ".swf";
            string OldWordPath = ContractPath + "PrintFiles/Word/" + PrintFileName + ".doc";
            if (((string.IsNullOrEmpty(PrintFileName) || PrintFileName.Trim() == "" || !File.Exists(HttpContext.Current.Server.MapPath(OldWordPath)) || !File.Exists(HttpContext.Current.Server.MapPath(OldFlashPath))) && isCreate == false) || isCreate == true)
            { 
                string OutFile = CreateWordApp(CD);
				if (!string.IsNullOrWhiteSpace(OutFile))
				{
					 OnChanged(OutFile);
					SaveToDatebase(contractId, OutFile);
					FlashPath = ContractPath + "PrintFiles/Swf/" + OutFile + ".swf";
					WordPath = ContractPath + "PrintFiles/Word/" + OutFile + ".doc";
					SuccessMark = true;
				}
				else
				{
					SuccessMark = false;
					ErrorStr += @"<script type='text/javascript'>$('#loadimg').hide();$('#result').html("+OutFile+"'未知错误:487！');</script>";
				}
               

                if (!string.IsNullOrEmpty(PrintFileName) && PrintFileName.Trim() != "")
                {
                   // if (File.Exists(HttpContext.Current.Server.MapPath(OldWordPath))) File.Delete(HttpContext.Current.Server.MapPath(OldWordPath));
                   // if (File.Exists(HttpContext.Current.Server.MapPath(OldFlashPath))) File.Delete(HttpContext.Current.Server.MapPath(OldFlashPath));
                }
            }
            else {
                FlashPath = OldFlashPath;
                WordPath = OldWordPath;
                SuccessMark = true;
            }
        }
        else
        {
            ErrorStr = @"<script type='text/javascript'>$('#loadimg').hide();$('#result').html('合同不存在！');</script>";
        }
    }

    public string FlashPath;

    public string WordPath;

    public bool SuccessMark;

    public string ErrorStr;

    public string ContractPath { get; set; }

    public string FlexPath { get; set; }

    public void SaveToDatebase(int contractid, string printFileName)
    {
        Contract.ContractDataContext ContractDataList = new Contract.ContractDataContext(PomPublicClass.POM_ConnectionString());
        var Result = ContractDataList.contract.SingleOrDefault<Contract.contract>(c => c.contractid == contractid);
        Result.PrintFileName = printFileName;
        ContractDataList.SubmitChanges();
    }

    public string CreateWordApp(ContractData CD)
    {
        string FileName = "";
        string newFile = "";
        string physicNewFile = "";
        string physicNewFile1 = "";
        try
        {
        DataCheck DC = new DataCheck();

        Application app = null;
        Document doc = null;
        app = new Application();
        app.Visible = false;
        doc = app.Documents.Add();

        app.ActiveDocument.PageSetup.TopMargin = app.CentimetersToPoints(float.Parse("2.3"));//上页边距
        app.ActiveDocument.PageSetup.BottomMargin = app.CentimetersToPoints(float.Parse("2.3"));//下页边距
        app.ActiveDocument.PageSetup.LeftMargin = app.CentimetersToPoints(float.Parse("2"));//左页边距
        app.ActiveDocument.PageSetup.RightMargin = app.CentimetersToPoints(float.Parse("2"));//右页边距
        app.ActiveDocument.PageSetup.FooterDistance = app.CentimetersToPoints(float.Parse("1.7"));//页脚



        app.Selection.ParagraphFormat.SpaceBefore = float.Parse("0");//段前间距
        app.Selection.ParagraphFormat.SpaceBeforeAuto = 0;//
        app.Selection.ParagraphFormat.SpaceAfter = float.Parse("0");//段后间距
        app.Selection.ParagraphFormat.SpaceAfterAuto = 0;//
        app.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;//单倍行距
        app.Selection.Font.NameFarEast = "宋体";
        app.Selection.Font.NameAscii = "Times New Roman";
        app.Selection.Font.NameOther = "Times New Roman";



        //oShape.WrapFormat.Type = WdWrapType.wdWrapInline;
        //oShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
        app.Selection.Font.Size = 18.0F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        app.Selection.TypeText("合同编号：" + DC.DataCheckResult(CD.ContractNo));
        app.Selection.TypeParagraph();

        app.Selection.Font.Size = 27.0F;
        app.Selection.TypeParagraph();
        app.Selection.Font.Bold = 1;
        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
        app.Selection.TypeText("厦门大学出版社有限责任公司");
        app.Selection.TypeParagraph();
        if (CD.ContractMain.HasValue && CD.ContractMain.Value > 0)
        {
            app.Selection.TypeText("图书出版补充合同");
        }
        else
        {
            app.Selection.TypeText("图书出版合同");
        }
        app.Selection.TypeParagraph();
        app.Selection.TypeParagraph();

        app.Selection.Font.Size = 18.0F;
        app.Selection.Font.Name = "楷体";
        app.Selection.Font.Bold = 0;
        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
        app.Selection.TypeText("书名：" + CD.Sm);
        app.Selection.TypeParagraph();

        if (!string.IsNullOrEmpty(CD.Csm) && CD.Csm.Trim() != "")
        {
            app.Selection.TypeText("丛书名：" + CD.Csm);
            app.Selection.TypeParagraph();
        }
        app.Selection.TypeParagraph();
        app.Selection.TypeParagraph();
        Microsoft.Office.Interop.Word.Table table = doc.Tables.Add(app.Selection.Range, 2, 2);
        table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;
        table.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderDiagonalDown].LineStyle = WdLineStyle.wdLineStyleNone;
        table.Borders[WdBorderType.wdBorderDiagonalUp].LineStyle = WdLineStyle.wdLineStyleNone;

        table.Columns[1].Width = app.CentimetersToPoints(2.8f);
        table.Columns[2].Width = app.CentimetersToPoints(9f);

        table.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalTop;
        table.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
        table.Cell(1, 1).Range.Font.Size = 18.0F;
        table.Cell(1, 1).Range.Font.Name = "黑体";
        table.Cell(1, 1).Range.Text = "甲方：";

        table.Cell(1, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalTop;
        table.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table.Cell(1, 2).Range.Font.Size = 18.0F;
        table.Cell(1, 2).Range.Font.Name = "黑体";
        table.Cell(1, 2).Range.Text = CD.Jiafang; ;

        table.Cell(2, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalTop;
        table.Cell(2, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
        table.Cell(2, 1).Range.Font.Size = 18.0F;
        table.Cell(2, 1).Range.Font.Name = "黑体";
        table.Cell(2, 1).Range.Text = "乙方：";

        table.Cell(2, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalTop;
        table.Cell(2, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table.Cell(2, 2).Range.Font.Size = 18.0F;
        table.Cell(2, 2).Range.Font.Name = "黑体";
        table.Cell(2, 2).Range.Text = "厦门大学出版社有限责任公司";

        object moveUnit = Microsoft.Office.Interop.Word.WdUnits.wdCell;
        object dummy = System.Reflection.Missing.Value;
        object moveCount = 1;
        object moveExtend = Microsoft.Office.Interop.Word.WdMovementType.wdMove;
        object what = WdGoToItem.wdGoToLine;
        object which = WdGoToDirection.wdGoToLast;
        object count = 99999999;

        app.Selection.GoTo(ref what, ref which, ref count, ref dummy);
        //app.Selection.Font.Size = 12.0F;
        //app.Selection.Font.Name = "黑体";
        //app.Selection.Font.Bold = 0;
        //app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
        app.Selection.TypeText("　");
        Shape shape = doc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 237.3f, 690f, 118.5f, 21.75f);
        //shape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringForward);
        shape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
        shape.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
        shape.TextFrame.TextRange.Font.Name = "黑体";
        shape.TextFrame.TextRange.Font.Size = 12.0F;
        shape.TextFrame.TextRange.Font.Bold = 0;
        shape.TextFrame.TextRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        shape.TextFrame.TextRange.Text = CD.Indate.HasValue?CD.Indate.Value.ToString("yyyy年MM月dd日"):DateTime.Now.ToString("yyyy年MM月dd日");
        //app.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;
        app.Selection.InsertBreak();

        app.Selection.Font.Size = 18.0F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
        if (CD.ContractMain.HasValue && CD.ContractMain.Value > 0)
        {
            app.Selection.TypeText("图 书 出 版 补 充 合 同");
        }
        else
        {
            app.Selection.TypeText("图 书 出 版 合 同");
        }
        app.Selection.TypeParagraph();
        app.Selection.Font.Size = 10.0F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 0;
        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;//水平居右
        app.Selection.TypeText("编号：" + DC.DataCheckResult(CD.ContractNo));
        app.Selection.TypeParagraph();

        app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;

        Microsoft.Office.Interop.Word.Table toptable = doc.Tables.Add(app.Selection.Range, 4, 4);
        toptable.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;
        toptable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
        toptable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
        toptable.Columns[1].Width = app.CentimetersToPoints(2.75f);
        toptable.Columns[2].Width = app.CentimetersToPoints(7.44f);
        toptable.Columns[3].Width = app.CentimetersToPoints(2.44f);
        toptable.Columns[4].Width = app.CentimetersToPoints(4.34f);

        toptable.Rows[1].Height = app.CentimetersToPoints(1.25f);
        toptable.Rows[2].Height = app.CentimetersToPoints(1.25f);
        toptable.Rows[3].Height = app.CentimetersToPoints(1.25f);
        toptable.Rows[4].Height = app.CentimetersToPoints(1.25f);

        Cell cell = toptable.Cell(1, 2);//行合并
        cell.Merge(toptable.Cell(1, 4));


        toptable.Cell(1, 1).Range.Text = "作品名称";
        toptable.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(1, 2).Range.Text = DC.DataCheckResult(CD.Sm);
        toptable.Cell(1, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(2, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(2, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(2, 2).Range.Text = DC.DataCheckResult(CD.Zuozhe);
        toptable.Cell(2, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(2, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(2, 3).Range.Text = "著作方式";
        toptable.Cell(2, 3).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(2, 3).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(2, 4).Range.Text = DC.DataCheckResult(CD.Zhuzuofangshi);
        toptable.Cell(2, 4).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(2, 4).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(3, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(3, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(3, 2).Range.Text = DC.DataCheckResult(CD.Danwei);
        toptable.Cell(3, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(3, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(3, 3).Range.Text = "联系人";
        toptable.Cell(3, 3).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(3, 3).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(3, 4).Range.Text = DC.DataCheckResult(CD.Zrbj);
        toptable.Cell(3, 4).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(3, 4).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(4, 1).Range.Text = "甲方";
        toptable.Cell(4, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(4, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(4, 2).Range.Text = DC.DataCheckResult(CD.Jiafang.Trim());
        toptable.Cell(4, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(4, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(4, 3).Range.Text = "乙方";
        toptable.Cell(4, 3).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(4, 3).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        toptable.Cell(4, 4).Range.Text = "厦门大学出版社有限责任公司";
        toptable.Cell(4, 4).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        toptable.Cell(4, 4).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;


        app.Selection.MoveDown();
        app.Selection.TypeText("作者");
        app.Selection.TypeParagraph();
        app.Selection.TypeText("（著作权人）");

        app.Selection.MoveDown();
        app.Selection.TypeText("作者");
        app.Selection.TypeParagraph();
        app.Selection.TypeText("单位/地址");

        app.Selection.GoTo(ref what, ref which, ref count, ref dummy);


        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;//水平居左
        doc.Paragraphs.Last.Range.Text = "";
        app.Selection.TypeParagraph();

        app.Selection.ParagraphFormat.SpaceBefore = float.Parse("0");//段前间距
        app.Selection.ParagraphFormat.SpaceBeforeAuto = 0;//

        app.Selection.ParagraphFormat.SpaceAfter = 6F;//段后间距
        app.Selection.ParagraphFormat.SpaceAfterAuto = 0;//
        app.Selection.ParagraphFormat.LineSpacing = 15F;//单倍行距

        //app.Selection.Font.Size = 10.5F;
        //app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.ParagraphFormat.FirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("甲乙双方就上述作品的出版达成如下协议：");
        app.Selection.TypeParagraph();

        ///第一条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第一条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 甲方授予乙方在合同有效期内，在");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Diqu));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("以");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Chubanxingshi));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("形式，用");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Wenti));
        if (CD.Wenti.Trim() == "外文") {
            app.Selection.TypeText(DC.DataCheckResult(CD.Qtwenti));
        }

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("文本出版发行上述作品的专有使用权。未经双方同意，任何一方不得将该使用权许可第三方使用。如有违反，另一方有权要求经济赔偿及终止合同。");

        if (CD.eCheck == 1)
        {
            app.Selection.Font.Name = "黑体";
            app.Selection.Font.Bold = 1;
            app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
            app.Selection.TypeText("同时甲方授予乙方在合同有效期内独家的信息网络传播权及转授权。");

        }
        app.Selection.TypeParagraph();
        ///第一条结束=====================================





        ///第二条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第二条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 甲方保证拥有本作品的著作权，保证本作品未侵犯他人著作权。如因上述权利的行使侵犯他人的权益，甲方承担全部责任并赔偿因此给乙方造成的损失，乙方可以终止合同。");
        app.Selection.TypeParagraph();
        ///第二条结束=====================================






        ///第三条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第三条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("甲方保证上述作品不含有 2011年3月19日国务院公布的《出版管理条例》第 25 条所禁止的内容：");
        app.Selection.ParagraphFormat.SpaceAfter = float.Parse("0");//段后间距
        app.Selection.ParagraphFormat.SpaceAfterAuto = 0;
        app.Selection.TypeParagraph();
        app.Selection.TypeText("1.反对宪法确定的基本原则的；2.危害国家统一、主权和领土完整的；3.泄露国家秘密、危害国家安全或者损害国家荣誉和利益的；4.煽动民族仇恨、民族歧视，破坏民族团结，或者侵害民族风俗、习惯的；5.宣扬邪教、迷信的；6.扰乱社会秩序，破坏社会稳定的；7.宣扬淫秽、赌博、暴力或者教唆犯罪的；8.侮辱或者诽谤他人，侵害他人合法权益的；9.危害社会公德或者民族优秀文化传统的；10.有法律、行政法规和国家规定禁止的其他内容的。");
        app.Selection.TypeParagraph();
        app.Selection.TypeText("如因含有该条例所禁止的内容给乙方造成损失，甲方应承担相应的责任。");
        app.Selection.ParagraphFormat.SpaceAfter = 6F;//段后间距
        app.Selection.ParagraphFormat.SpaceAfterAuto = 0;
        app.Selection.TypeParagraph();
        ///第三条结束=====================================




        ///第四条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第四条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 甲方应于");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //CD.Jiaogaoshijian
        app.Selection.TypeText(DC.DataCheckResult(CD.Jiaogaoshijian));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("前将上述作品齐、清、定的原稿（可以是手写稿、打印稿或符合要求的电子文本）交付乙方。甲方因故不能按时交稿，应在交稿期限届满前 10 日通知乙方，双方另行约定交稿日期。甲方到期仍不能交稿，乙方可以终止合同。");
        app.Selection.TypeParagraph();
        ///第四条结束=====================================






        ///第五条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第五条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 上述作品由乙方进行编、审、校工作。甲方许可乙方对上述作品进行修改、删节和技术处理。如有重大的修改或删节，则应在发稿前征得甲方同意。乙方如认为所交作品质量不符合出版要求，可将原稿退还作者修改，退修后出书时间按退修时间加倍顺延。");
        app.Selection.TypeParagraph();
        ///第五条结束=====================================





        ///第六条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第六条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 上述作品实际字数为");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        /*
        double? tmpZs;
        if (CD.Zs.HasValue == true)
        {
            tmpZs = (double)CD.Zs / 10;
        }
        else
        {
            tmpZs = null;
        }
         */
        app.Selection.TypeText(DC.DataCheckResult(CD.Zs / 10));
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("万字，采用");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Kb));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("开本，封面用纸标准为");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Fmyz));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("克");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Fmyz1));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("纸，环衬用纸为");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Hcyz));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("克");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Hcyz1));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("纸，彩插用纸为");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Ccyz));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("克");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Ccyz1));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("纸，内文用纸标准为");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Nwyz));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("克");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Nwyz1));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("纸，全书采用");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Baozhuang));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("。");
        app.Selection.TypeParagraph();
        ///第六条结束=====================================






        ///第七条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第七条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 乙方应于");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Cssj));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("前出版上述作品的纸质图书，因故不能按时出版，应在出版期限届满前 10 日通知甲方，双方另行约定出版日期。");
        app.Selection.TypeParagraph();
        ///第七条结束=====================================


        ///第八条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第八条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 乙方向甲方支付稿酬的办法、标准及发放时间。");
        app.Selection.TypeParagraph();
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Name = "楷体";
        if (string.IsNullOrEmpty(CD.Qtcontent) == true || CD.Qtcontent.Trim() == "")
        {
            app.Selection.TypeText("无");
        }
        else
        {
            app.Selection.TypeText(CD.Qtcontent);
        }
        app.Selection.TypeParagraph();
        ///第八条结束=====================================
        ///


        ///第九条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第九条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 上述作品首次出版30日内，乙方向甲方赠样书");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Yangshu));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("册，并以");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Zhekou));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("折价售予甲方图书");


        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Goushu));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("册，其书款共计");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(" " + new RMBCapitalization().RMBAmount(DC.DataCheckResult((double)CD.Shoukuan)) + " ");

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("（￥");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(" " + DC.DataCheckResult((double)CD.Shoukuan).ToString("0.00") + " ");

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("） , 甲方应于");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Shoukuandate));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("前交付。");

        app.Selection.TypeParagraph();
        ///第九条结束=====================================





        ///第十条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第十条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 在合同有效期内，乙方如需重印本书，应事先通知甲方并获甲方同意。如果甲方需要对作品进行修改，应于收到通知后 10 日内答复乙方，否则乙方可按原版重印。乙方重印，应将印数通知甲方，并按第八条所订标准向甲方支付报酬。如未约定，另订协议。");
        app.Selection.TypeParagraph();
        ///第十条结束=====================================
        ///



        ///第十一条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第十一条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 乙方与第三方合作使用或授权第三方使用本作品的电子出版专有权及信息网络传播权，应将所签订的合同文本复印件送交甲方，并将实际所得净收益的");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Jingshouyi));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("%交付甲方。");
        app.Selection.TypeParagraph();
        ///第十一条结束=====================================





        ///第十二条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第十二条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 在合同有效期内，甲方不得将上述作品的全部或一部分，或将其内容稍加修改以原名称或更换名称授予第三方另行出版（包括纸质图书和电子图书）、信息网络传播、翻译、录制电子、音像制品，如违反本条规定，甲方负责赔偿由此给乙方造成的损失。甲方若许可第三方出版含上述作品的选集或文集，应事先征得乙方同意并另行签约。在合同有效期内，乙方有权出版上述作品的修订本、缩编本，但应与甲方另行签约。");
        app.Selection.TypeParagraph();
        ///第十二条结束=====================================





        ///第十三条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第十三条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 甲乙双方均可与海外出版单位洽谈版权贸易，但在签订合同前应通知对方并征得对方同意，将合同文本的复印件及实际所得收益的");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Jingshouyi));

        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("%交付对方。");
        app.Selection.TypeParagraph();
        ///第十三条结束=====================================
        ///



        ///第十四条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第十四条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 其他事项");
        app.Selection.TypeParagraph();
        app.Selection.Font.Name = "楷体";
        app.Selection.Font.Bold = 1;
        if (string.IsNullOrEmpty(CD.Content) == true || CD.Content.Trim() == "")
        {
            app.Selection.TypeText("无");
        }
        else
        {
            app.Selection.TypeText(CD.Content);
        }
        app.Selection.TypeParagraph();
        ///第十四条结束=====================================
        ///




        ///第十五条开始=====================================
        //app.Selection.Font.Size = 10.5F;
        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        //app.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = app.CentimetersToPoints(0.74F);//左缩进
        app.Selection.TypeText("第十五条");
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText(" 本合同一式两份，双方各执一份为凭，效力相同。本合同有效期为");

        app.Selection.Font.Name = "黑体";
        app.Selection.Font.Bold = 1;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineSingle;
        app.Selection.TypeText(DC.DataCheckResult(CD.Youxiaoqi));
        app.Selection.Font.Name = "宋体";
        app.Selection.Font.Bold = 0;
        app.Selection.Font.Underline = WdUnderline.wdUnderlineNone;
        app.Selection.TypeText("年，自双方代表全部签字之日起生效。合同的变更、续签及其他未尽事宜，由双方另行商定。");
        app.Selection.TypeParagraph();
        
        ///第十五条结束=====================================
        //app.Selection.TypeParagraph();
        float focusleft = (float)app.Selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage);
        float focustop = (float)app.Selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage);
		
       // app.Selection.TypeText(focusleft.ToString()+ " " +focustop.ToString());
        app.Selection.GoTo(ref what, ref which, ref count, ref dummy);
		WdStatistic stat1 = WdStatistic.wdStatisticPages;
        int PageCount1 = doc.ComputeStatistics(stat1);
        Shape shape1 = doc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 14.55f, focustop, 455.4f, 180f);
        //shape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringForward);
        shape1.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapInline ;
        shape1.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
        shape1.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionLine;
        shape1.TextFrame.TextRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        //shape1.TextFrame.TextRange.Text = DateTime.Now.ToString("yyyy年MM月dd日");

        Microsoft.Office.Interop.Word.Table table1 = doc.Tables.Add(shape1.TextFrame.ContainingRange, 6, 2);
        table1.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;
        table1.Rows.Height = app.CentimetersToPoints(1f);
        table1.Columns[1].Width = app.CentimetersToPoints(8.29f);
        table1.Columns[2].Width = app.CentimetersToPoints(8.07f);
        table1.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(1, 1).Range.Text = "甲方（代表）：";
        table1.Cell(1, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(1, 2).Range.Text = "乙方：厦门大学出版社有限责任公司";
        table1.Cell(2, 1).Range.Text = "";
        table1.Cell(2, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(2, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(2, 2).Range.Text = "责任编辑：";
        table1.Cell(3, 1).Range.Text = "";
        table1.Cell(3, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(3, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(3, 2).Range.Text = "法人代表：";
        table1.Cell(4, 1).Range.Text = "";
        table1.Cell(4, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(4, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(4, 2).Range.Text = "开户银行：工商行厦大支行";
        table1.Cell(5, 1).Range.Text = "";
        table1.Cell(5, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(5, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(5, 2).Range.Text = "账号：4100021709024902266";
        table1.Cell(6, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(6, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(6, 1).Range.Text = "签订日期：       年    月    日 ";
        table1.Cell(6, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
        table1.Cell(6, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
        table1.Cell(6, 2).Range.Text = "签订日期：       年    月    日 ";

        float newfocustop = (float)app.Selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage);
        //app.Selection.TypeText(focusleft.ToString() + " " + newfocustop.ToString());

        WdStatistic stat2 = WdStatistic.wdStatisticPages;
        int PageCount2 = doc.ComputeStatistics(stat2);
        if (PageCount1 < PageCount2)
        {
            shape1.Top = 0f;
        }
        //判断页码是否增加 
        object missing = System.Reflection.Missing.Value;
        object linkToFile = false;
        object saveWithDocument = true;
        object top = 50;

        app.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = -1;
        app.ActiveWindow.View.SeekView = WdSeekView.wdSeekFirstPageFooter;
        app.Selection.TypeText("");
        app.Selection.ClearFormatting();

        app.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryFooter;
        app.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
        app.Selection.TypeText("第");
        object page = WdFieldType.wdFieldPage;
        app.Selection.Fields.Add(app.Selection.Range, ref page, ref missing, ref missing);
        app.Selection.TypeText("页 共");
        object pages = WdFieldType.wdFieldNumPages;
        app.Selection.Fields.Add(app.Selection.Range, ref pages, ref missing, ref missing);
        app.Selection.TypeText("页");


        doc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekFirstPageHeader;
        app.Selection.ClearFormatting();
        doc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
        app.Selection.ClearFormatting();

        newFile = DateTime.Now.ToString("yyyyMMddHHmmssss") ;
        physicNewFile = HttpContext.Current.Server.MapPath(ContractPath + "PrintFiles/Word/" + newFile + ".doc");
        physicNewFile1 = HttpContext.Current.Server.MapPath(ContractPath + "tmp/" + newFile + ".pdf");
        doc.SaveAs(physicNewFile);
        doc.SaveAs(physicNewFile1, 17);
        if (doc != null)
        {
            doc.Close();//关闭文档
        }

        if (app != null)
        {
            app.Quit();//退出应用程序
        }

        FileName = newFile;
        return FileName;
           }
           catch (Exception ex)
           {
			   ErrorStr +=physicNewFile + ex.ToString();
               FileName = "";
               if (physicNewFile1 != "" && File.Exists(physicNewFile1)) File.Delete(physicNewFile1);
               if (physicNewFile != "" && File.Exists(physicNewFile)) File.Delete(physicNewFile);
               SuccessMark = false;
               ErrorStr += @"<script type='text/javascript'>$('#loadimg').hide();$('#result').html('文档转换出现错误！');</script>";
			   string errorLog = HttpContext.Current.Server.MapPath("~/App_Data/Error.log");
				System.IO.FileStream fs = new System.IO.FileStream(errorLog, System.IO.FileMode.Append, System.IO.FileAccess.Write);
				System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
				//Exception ex = HttpContext.Current.Server.GetLastError();
				string IP = "";//客户端IP
				HttpRequest request = HttpContext.Current.Request;
				string result = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
				if (null == result || result == String.Empty)
				{
					IP = request.ServerVariables["REMOTE_ADDR"];
				}
				else if (request.ServerVariables["HTTP_VIA"] != null)
				{
					IP = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
				}
				else
				{
					IP = request.UserHostAddress;
				}
				if (ex.InnerException != null)
				{
					sw.WriteLine("IP:{0}\n时间:{1}\n错误消息:{2}\n位置:{3}\n地址：{4}\n\n", IP,DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss ffff"), ex.ToString(), ex.InnerException, HttpContext.Current.Request.Url.AbsolutePath);
				}
				else if (ex != null)
				{
					sw.WriteLine("IP:{0}\n时间:{1}\n错误消息:{2}\n地址：{3}\n\n", IP,DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss ffff"), ex.ToString(), HttpContext.Current.Request.Url.AbsolutePath);
				}
				else
				{
					sw.WriteLine("未知错误");
				}
				//Server.ClearError();
				sw.Close(); 

               return FileName;
           }
    }

    public ContractData ContractDataMatch(ContractDataForLinq cd)
    {
        ContractData CD = new ContractData();
        CD.ContractNo = cd.contractno;
        CD.ContractMain = cd.Contract_Main;
        CD.Sm = cd.sm;
        CD.Csm = cd.csm;
        CD.Zuozhe = cd.zuozhe;
        CD.Zhuzuofangshi = cd.zhuzuofangshi;
        CD.Danwei = cd.danwei;
        CD.Zrbj = cd.zrbj;
        CD.Jiafang = cd.jiafang;
        CD.Chubanxingshi = cd.chubanxingshi;
        CD.eCheck = cd.chubanxingshi.IndexOf("电子图书") >= 0 ? 1 : 0;
        CD.Diqu = cd.diqu;
        CD.Wenti = cd.wenti;
        CD.Qtwenti = cd.qtwenti;
        CD.Jiaogaoshijian = cd.jiaogaoshijian;
        CD.Indate = cd.indate;
        CD.Zs = cd.zs;
        CD.Kb = cd.kb;
        CD.Fmyz = cd.fmyz;
        CD.Fmyz1 = cd.fmyz1;
        CD.Hcyz = cd.hcyz;
        CD.Hcyz1 = cd.hcyz1;
        CD.Ccyz = cd.ccyz;
        CD.Ccyz1 = cd.ccyz1;
        CD.Nwyz = cd.nwyz;
        CD.Nwyz1 = cd.nwyz1;
        CD.Baozhuang = cd.baozhuang;
        CD.PrintFileName = cd.PrintFileName;

        DateTime CssjOut;
        if (string.IsNullOrEmpty(cd.cssj) || cd.cssj.Trim() == "")
        {
            CD.Cssj = null;// 
        }
        else if (DateTime.TryParse(cd.cssj, out CssjOut) == false)
        {
            CD.Cssj = null;
        }
        else
        {
            CD.Cssj = CssjOut;
        }
        CD.Qtcontent = cd.qtcontent;
        CD.Yangshu = cd.yangshu;
        CD.Zhekou = cd.zhekou;
        CD.Goushu = cd.goushu;
        CD.Shoukuan = cd.shoukuan;

        DateTime ShoukuandateOut;
        if (string.IsNullOrEmpty(cd.shoukuandate) || cd.shoukuandate.Trim() == "")
        {
            CD.Shoukuandate = null;// 
        }
        else if (DateTime.TryParse(cd.shoukuandate, out ShoukuandateOut) == false)
        {
            CD.Shoukuandate = null;
        }
        else
        {
            CD.Shoukuandate = ShoukuandateOut;
        }

        CD.Jingshouyi = cd.jingshouyi;
        CD.Content = cd.content;
        int YouxiaoqiOut;
        if (string.IsNullOrEmpty(cd.youxiaoqi) || cd.youxiaoqi.Trim() == "")
        {
            CD.Youxiaoqi = null;
        }
        else if (int.TryParse(cd.youxiaoqi, out YouxiaoqiOut) == false)
        {
            CD.Youxiaoqi = null;
        }
        else
        {
            CD.Youxiaoqi = YouxiaoqiOut;
        }
        CD.isStatus = cd.isStatus;

        return CD;
    }

    private static bool KillProcess(int pid)
    {
        Process[] procs = Process.GetProcesses();
        for (int i = 0; i < procs.Length; i++)
        {
            if (GetParentProcess(procs[i].Id) == pid)
                KillProcess(procs[i].Id);
        }
        try
        {
            Process myProc = Process.GetProcessById(pid);
            myProc.Kill();
        }
        catch (ArgumentException)
        {

        }
        return true;
    }

    private static int GetParentProcess(int Id)
    {
        int parentPid = 0;
        using (System.Management.ManagementObject mo = new System.Management.ManagementObject("win32_process.handle='" + Id.ToString(CultureInfo.InvariantCulture) + "'"))
        {
            try
            {
                mo.Get();
            }
            catch (ManagementException)
            {
                return -1;
            }
            parentPid = Convert.ToInt32(mo["ParentProcessId"], CultureInfo.InvariantCulture);
        }
        return parentPid;
    }

    private string OnChanged(string fileName)
    {
        if (fileName == "") return "";
        string inFile = HttpContext.Current.Server.MapPath(ContractPath + "tmp/" + fileName + ".pdf");
        string outFile = HttpContext.Current.Server.MapPath(ContractPath + "PrintFiles/Swf/" + fileName + ".swf");
        string flashPrinter = HttpContext.Current.Server.MapPath("pdf2swf.exe");
        StringBuilder sb = new StringBuilder();
        sb.Append(" -z");
        sb.Append(" -T 9");//flash version  
        sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)
        sb.Append(" -s disablelinks");//禁止PDF里面的链接  
        sb.Append(" \"" + inFile + "\"");//input  
        sb.Append(" -o \"" + outFile + "\"");//output

        Process pss = new Process();
        pss.StartInfo.CreateNoWindow = false;
        pss.StartInfo.FileName = flashPrinter;
        pss.StartInfo.Arguments = sb.ToString();
        pss.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        try
        {
            pss.Start();
            pss.WaitForExit(2000);
            //如果进程还未结束，杀死进程树
            if (!pss.HasExited) KillProcess(pss.Id);
            if (File.Exists(inFile)) File.Delete(inFile);
            return outFile;
        }
        catch (Exception)
        {
            SuccessMark = false;
            ErrorStr = @"<script type='text/javascript'>$('#loadimg').hide();$('#result').html('文档转换出现错误！');</script>";
            //如果报错 将输出文件删除
            if (File.Exists(outFile)) File.Delete(outFile);
            outFile = "";
            //如果进程还未结束，杀死进程树
            if (!pss.HasExited) KillProcess(pss.Id);
            return outFile;
        }
    }
}